﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace EulerLib
{
    public class EulerUtils
    {
        public static bool IsPrime(long num, List<long> primes)
        {
            long max = (long)Math.Floor(Math.Sqrt(num));

            for (int i = 0; i < primes.Count && max >= primes[i]; i++)
            {
                if (num % primes[i] == 0)
                {
                    return false;
                }
            }

            return true;
        }

        public static List<long> GeneratePrimesUpTo(long maxNum)
        {
            List<long> primes = new List<long>() { 2 };

            for (long i = 3; i <= maxNum; i += 2)
            {
                if (IsPrime(i, primes))
                {
                    primes.Add(i);
                }
            }

            return primes;
        }

        public static bool WithinBoundaries(int x, int y, int minx, int maxx, int miny, int maxy)
        {
            if (x < minx)
                return false;

            if (x > maxx)
                return false;

            if (y < miny)
                return false;

            if (y > maxy)
                return false;

            return true;
        }
    }
}
